from torchvision import models
from torchvision import transforms
from PIL import Image
import torch


def main():

    t_c = [0.5, 14.0, 15.0, 28.0, 11.0, 8.0, 3.0, -4.0, 6.0, 13.0, 21.0]
    t_u = [35.7, 55.9, 58.2, 81.9, 56.3, 48.9, 33.9, 21.8, 48.4, 60.4, 68.4]
    t_c = torch.tensor(t_c)
    t_u = torch.tensor(t_u)

    # In[5]:
    w = torch.ones(())
    b = torch.zeros(())
    t_p = model(t_u, w, b)
    print(f"t_p = {t_p}")
    loss = loss_fn(t_p, t_c)
    print(f"loss = {loss}")

    w_change(t_u, t_c, w, b)
def w_change(t_u, t_c, w, b):
    # In[8]:
    delta = 0.1
    loss_rate_of_change_w = \
        (loss_fn(model(t_u, w + delta, b), t_c) -
         loss_fn(model(t_u, w - delta, b), t_c)) / (2.0 * delta)
    print(f"loss_rate_of_change_w = {loss_rate_of_change_w}")
def model(t_u, w, b):
    return w * t_u + b

def loss_fn(t_p, t_c):
    squared_diffs = (t_p - t_c)**2
    print(f"squared_diffs = {squared_diffs}")
    return squared_diffs.mean()

if __name__ == '__main__':
    main()
